import re
import openpyxl
text = open(r"C:\Users\LENOVO\Desktop\test1.txt",encoding='utf-8')
data = text.read()
pattern = r"(\d{4}[年/-]\d{1,2}[月]?)"
dates = re.findall(pattern, data)
# 创建一个工作簿对象
workbook = openpyxl.Workbook()
# 创建一个工作表对象
sheet = workbook.active
# 循环遍历数据，将每个数据写入Excel文件中
for row in dates:
    sheet.append([row])
# 保存Excel文件
workbook.save('ymData.xlsx')